
*------------------------------------------------------------------------------*
* Special Case of ASPM: Veto player incl. Swiss "Volksmedian" based on referendum
*
* Version:	2016-06-13
* Changes:	2016-??-??: First release
*------------------------------------------------------------------------------*


* "VOLKSMEDIAN"
* -------------

* Merge external data on Swiss referenda
merge 1:1 id using "datasets/swi_referenda", keep(match master) nogen

by g101 g105, sort: egen zs = max(countsum)
replace countsum = zs
drop zs


* Weigh party positions with aligned recommendations
gen weight = volks * $ideology
by g101 g105, sort: egen sum = sum(weight)
gen zs = sum / countsum
 
* Interpolate	
by p101, sort: ipolate zs g105, gen(vm_swi)
sort p101 g105
replace vm_swi = vm_swi[_n-1] if vm_swi == . & p101 == p101[_n-1]



* VETOPLAYER
* ----------


* Minimum and maximum of government parties (and minority partners if previously selected)
gen zsp103 = 1 if p103 == 1
capture: replace zsp103 = 1 if minogov_dummy == 1 & minority == 1

gen zsgov = $ideology if zsp103 == 1
by g101 g105, sort: egen govmin = min(zsgov)
by g101 g105, sort: egen govmax = max(zsgov)

* Fallback
replace govmin = median1st if govmin == . & GOV_POS == median1st
replace govmax = median1st if govmax == . & GOV_POS == median1st



* Range
gen VP_RANGE = max(govmax,median1st,median2nd,vm_swi) - min(govmin,median1st,median2nd,vm_swi)



* Cleansing
replace govmin	 = . if g106 == 9
replace govmax	 = . if g106 == 9
replace VP_RANGE = . if g106 == 9

lab var govmin "Minimum position within government"
lab var govmax "Maximum position within government"
lab var vm_swi "Median voter based on referendums (SWI)"	
lab var VP_RANGE "Veto player range"

sort g101 g105 p101

capture: macro drop vetoplayer
capture: drop volks countsum weight sum zs*
